package py.com.mblj.server;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import org.hibernate.Session;
import org.hibernate.Transaction;
import py.com.mblj.client.GWTService;
import py.com.mblj.domain.Denuncias;
import py.com.mblj.util.HibernateUtil;

/**
 *
 * @author markos
 */
public class GWTServiceImpl extends RemoteServiceServlet implements GWTService {
    /**
	 * 
	 */
	private static final long serialVersionUID = 5524026469117596777L;

	/**
     * Metodo para gestion de las denuncias (ABM)
     *
     * @param d
     * @return
     */
    @SuppressWarnings("finally")
	public Boolean guardarDenuncia(Denuncias d, Integer op) 
    {
        Boolean retorno = false;
        try
        {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            Transaction tran = session.beginTransaction();
            switch (op)
            {
                case HibernateUtil.OP_INSERT:
                    session.save(d);
                    break;
                case HibernateUtil.OP_DELETE:
                    Denuncias mgdDenuncia = (Denuncias) session.merge(d);
                    session.delete(mgdDenuncia);
                    break;
                case HibernateUtil.OP_UPDATE:
                    session.merge(d);
                    break;
            }
            tran.commit();
            retorno = true;
        } 
        catch (Exception e)
        {
            
        }
        finally
        {
            return retorno;
        }
    }
}
